package com.ljm.factory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;

public class DaoFactory {
	private static Properties daoConfig = new Properties();

	static {
		InputStream in = DaoFactory.class.getClassLoader().getResourceAsStream(
				"dao.properties");
		try {
			daoConfig.load(in);
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	private DaoFactory() {

	}

	private static DaoFactory instance = new DaoFactory();

	public static DaoFactory getInstance() {
		return instance;
	}

	public static <T> T createDao(Class<T> clazz) {

		String daoName = daoConfig.getProperty(clazz.getSimpleName());
		try {
			T dao = (T) Class.forName(daoName).newInstance();
			return dao;
		} catch (Exception e) {
			throw new RuntimeException(e);
		}

	}
}
